// var i;
// var $item_Setting_UIBindings = require("./Item_Setting_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $audioManager = require("./AudioManager");
// var u = cc._decorator;
// var d = u.ccclass;
// var p = u.property;
// var h = u.inspector;
// var f = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onEnable = function () {
//         this._refersh();
//         this.auto_ui.addClickListener(this._clickListener, this);
//     };
//     t.prototype._clickListener = function (e) {
//         switch (e) {
//             case this.auto_ui.btn_music:
//                 $audioManager.AudioMgr.isMusic = $audioManager.AudioMgr.isEffect = !$audioManager.AudioMgr.isMusic;
//                 break;
//             case this.auto_ui.btn_shake:
//                 this.auto_ui.node_off_shake.active = !this.auto_ui.node_off_shake.active;
//         }
//         this._refersh();
//     };
//     t.prototype._refersh = function () {
//         this.auto_ui.node_off_music.active = !$audioManager.AudioMgr.isMusic;
//     };
//     __decorate([p($item_Setting_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([d], t);
// })($resKeeper.default);
// exports.default = f;
import ItemSettingUIBindings from "./Item_Setting_UIBindings";
import ResKeeper from "./ResKeeper";
import { AudioMgr } from "./AudioManager";

const { ccclass, property, inspector } = cc._decorator;

/**
 * 建议类名：SettingsUIManager
 */
@ccclass
class ItemSetting extends ResKeeper {
    @property(ItemSettingUIBindings)
    auto_ui: ItemSettingUIBindings = null;

    /**
     * 当组件启用时调用，初始化 UI 并添加点击监听器
     * 建议方法名：handleEnable
     */
    onEnable(): void {
        this._refreshUI();
        this.auto_ui.addClickListener(this._handleClick, this);
    }

    /**
     * 点击事件监听器，根据点击的按钮执行相应操作
     * @param event 点击事件
     * 建议方法名：handleClick
     */
    private _handleClick(event: any): void {
        switch (event) {
            case this.auto_ui.btn_music:
                // 切换音效状态
                let musicStatus = AudioMgr.isMusicOn;
                let effectStatus = !musicStatus;
                AudioMgr.toggleMusic(effectStatus);
                break;
            case this.auto_ui.btn_shake:
                // 切换震动状态
                this.auto_ui.node_off_shake.active = !this.auto_ui.node_off_shake.active;
                break;
        }
        this._refreshUI();
    }

    /**
     * 刷新 UI 状态，根据音效状态更新按钮显示
     * 建议方法名：updateUI
     */
    private _refreshUI(): void {
        this.auto_ui.node_off_music.active = !AudioMgr.isMusicOn;
    }
}

export default ItemSetting;